<!DOCTYPE html>

<head>
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script src="https://www.paypalobjects.com/api/checkout.js"></script>
</head>

<body>
  <div id="paypal-button"></div>

  <script>
      paypal.Button.render({
          locale: 'zh_CN', // or en_US
          env: 'sandbox', // or sandbox,production

          commit: true, // Show a 'Pay Now' button
          client: {
              sandbox:    'AdfZDMpAtgBPxeOLHo1kwWkV2EDxvv2YOsEu7xp905Oyo7pLnMVWtWDfvV3V7BTzGcI6CphAmnNvfcNJ',
              production: 'AS5bxiYwf6aty_nyad6nxdShSIYHIWewNzwaXqmwHC1vggioiRB01z3kEHQOEycdk-1fBLuhTmOFLAoT'
          },
          style: {
              size: 'small',
              color: 'silver',
              shape: 'pill',
              label: 'checkout',
              tagline: false
          },

          payment: function(data, actions) {
              return actions.payment.create({
                  payment: {
                      transactions: [
                          {
                              amount: { total: '10.00', currency: 'USD' }
                          }
                      ]
                  }
              });
          },

          onAuthorize: function(data, actions) {
              return actions.payment.execute().then(function(payment) {
                  $.ajax({
                    type: 'POST',
                    url: '/',
                    data: {}
                  }).done(function (data) {
                      if (data == '0') {
                          alert('The payment is complete!');
                          window.location.reload();
                      }else {
                          alert('pay fail')
                      }
                  })
              });
          },

          onCancel: function(data, actions) {
          },

          onError: function(err) {
          }
      }, '#paypal-button');
  </script>
</body>

